package com.uyaer.wheel.common
{
	import flash.filesystem.File;
	import flash.filesystem.FileMode;
	import flash.filesystem.FileStream;
	import flash.net.SharedObject;

	public class Config
	{
		public static var platform:String = "web";
		
		/**
		 *图片素材地址 
		 */		
		public static var textureSource:String = "assets/texture/";
		public static var audioSource:String = "assets/audio/";
		
		/**
		 *素材标准宽带(素材按照这个标准制作的) 
		 */		
		public static var BASIC_W:int = 640;
		
		public static var debug:Boolean = false;
		private static var _MUSIC:Boolean = true;
		private static var _isUp:Boolean = false; //方向是否向上

		private static var data:Object;
		
		
		/**
		 *从文件中读取配置 
		 * 
		 */		
		public static function read():void{
			if(Config.platform == Platform.WEB){
				var shared:SharedObject = SharedObject.getLocal("config");
				data = shared.data.config;
			}else{
				var file:File = File.userDirectory.resolvePath("com.uyaer.wheel.config.db");
				var fileStream:FileStream = new FileStream();
				if(file.exists){
					fileStream.open(file,FileMode.READ);
					data = fileStream.readObject();
				}else{
					data = null;
				}
			}
			if(data){
				_MUSIC = data.music;
				_isUp = data.isUp;
			}else{
				_MUSIC = true;
				_isUp = true;
			}
		}
		
		/**
		 *保存配置
		 * 
		 */		
		public static function save():void{
			data = new Object();
			data.music = _MUSIC;
			data.isUp = _isUp;
			if(Config.platform == Platform.WEB){
				var shared:SharedObject = SharedObject.getLocal("config");
				shared.data.config = data;
			}else{
				var file:File = File.userDirectory.resolvePath("com.uyaer.wheel.config.db");
				var fileStream:FileStream = new FileStream();
				fileStream.open(file,FileMode.WRITE);
				fileStream.writeObject(data);
				fileStream.close();
			}
		}

		/**
		 * 是否播放音乐
		 */
		public static function get MUSIC():Boolean{
			return _MUSIC;
		}

		/**
		 * @private
		 */
		public static function set MUSIC(value:Boolean):void{
			_MUSIC = value;
			save();
		}

		public static function get isUp():Boolean{
			return true;
//			return _isUp;
		}

		public static function set isUp(value:Boolean):void{
			_isUp = value;
			save();
		}


	}
}